﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DONGACS.Common;
using DONGACS.Domain;

namespace DONGACS.DAO
{
    public class RolesInPathsDao: AccessData
    {
        //Lấy tất cả RolesInPaths của một Role
        public IList<RolesInPaths> GetRolesInPathsByRolesId(string roleId)
        {
            CommandText = "Select * From TB_RolesInPaths as R Where R.RoleId = " + roleId +
                          " and R.IsDelete = 0 and R.IsEnable = 1";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();
            IList<RolesInPaths> list = CollectionHelper.ConvertTo<RolesInPaths>(table);
            return list;
        }

        //Xóa tất cả RolesInPaths của một Role
        public bool DeleteRolesInPathsByRolesId(string roleId)
        {
            CommandText = "Delete From TB_RolesInPaths Where RoleId = " + roleId;
            Commandtype = CommandType.Text;

            return Save();
        }

        //Đếm số RolesInPaths của  một Roles
        public int CountRolesInPathsByRoleId(string roleId)
        {
            CommandText = "Select * From TB_RolesInPaths as R Where R.RoleId = " + roleId +
                          " and R.IsDelete = 0 and R.IsEnable = 1";
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();
            IList<RolesInPaths> list = CollectionHelper.ConvertTo<RolesInPaths>(table);
            return list.Count;
        }

        //Lấy tất cả RolesInPaths theo PathId
        public IList<RolesInPaths> GetAllRolesInPathsByPathId(string pathId)
        {
            CommandText = "Select * From TB_RolesInPaths as R where R.PathId = " + pathId;
            Commandtype = CommandType.Text;

            DataTable table = GetDataTable();

            IList<RolesInPaths> list = CollectionHelper.ConvertTo<RolesInPaths>(table);

            return list;

        }

        public bool AddNewRolesInPaths(RolesInPaths rolesInPaths)
        {
            return Insert("TB_RolesInPaths", rolesInPaths);
        }
    }
}
